package com.baimifan.renovation.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.baimifan.renovation.R;
import com.baimifan.renovation.model.TaskData;
import com.baimifan.renovation.view.TaskHolder;

import org.xutils.x;

import java.util.ArrayList;

/**
 * Created by baimifan on 2017/06/21.
 */

public class TaskAdapter extends RecyclerView.Adapter<TaskHolder> {
    private ArrayList<TaskData> mlists;
    private Float w, h;

    public TaskAdapter (ArrayList<TaskData> lists, Float w, Float h) {
        this.mlists = lists;
        this.w = w;
        this.h = h;
    }

    @Override
    public TaskHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.task_item, parent, false);
        TaskHolder taskHolder = new TaskHolder(view);
        return taskHolder;
    }

    @Override
    public void onBindViewHolder(TaskHolder holder, int position) {
        LinearLayout.LayoutParams params_iv = new LinearLayout.LayoutParams((int)(w*98), (int)(h*82));
        params_iv.setMargins((int)(w*15),(int)(12.4*h), (int)(w*15), 0);
        holder.iv.setLayoutParams(params_iv);
        LinearLayout.LayoutParams params_title = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, (int)(h*48));
        params_title.setMargins((int)(w*15), (int)(h*11.4), 0, (int)(h*16));
        holder.title.setLayoutParams(params_title);
        RelativeLayout.LayoutParams params_price = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params_price.setMargins((int)(w*15), 0, 0, 0);
        params_price.addRule(RelativeLayout.CENTER_VERTICAL);
        holder.price.setLayoutParams(params_price);
        RelativeLayout.LayoutParams params_date = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params_date.setMargins((int)(w*127), 0, 0, 0);
        params_date.addRule(RelativeLayout.CENTER_VERTICAL);
        holder.date.setLayoutParams(params_date);
        LinearLayout.LayoutParams params_tag = new LinearLayout.LayoutParams(
                (int)(w*330), 2);
        params_tag.setMargins((int)(w*15), (int)(h*5), 0, (int)(h*5.6));
        holder.tag.setLayoutParams(params_tag);
        TaskData taskData = mlists.get(position);
        holder.title.setText(taskData.getTitle());
        holder.price.setText("¥" + taskData.getRwyj());
        holder.date.setText("预计" + taskData.getStartTime() + "开工");
        x.image().bind(holder.iv, taskData.getImg());
    }

    @Override
    public int getItemCount() {
        return mlists.size();
    }


}
